<?php

/**
 * Description of FileSystemUtils
 *
 * @author ealesfi
 */
class FileSystemUtils {

    //put your code here

    private $maxFileSize = 2097152; // 2MB in bytes

    public function getMaxFileSize() {
        return $this->maxFileSize;
    }

    public function normalize_special_characters($str) {
        # Quotes cleanup 
        $str = ereg_replace(chr(ord("`")), "'", $str);        # ` 
        $str = ereg_replace(chr(ord("´")), "'", $str);        # ´ 
        $str = ereg_replace(chr(ord("„")), ",", $str);        # „ 
        $str = ereg_replace(chr(ord("`")), "'", $str);        # ` 
        $str = ereg_replace(chr(ord("´")), "'", $str);        # ´ 
        $str = ereg_replace(chr(ord("“")), "\"", $str);        # “ 
        $str = ereg_replace(chr(ord("”")), "\"", $str);        # ” 
        $str = ereg_replace(chr(ord("´")), "'", $str);        # ´ 

        $unwanted_array = array('Š' => 'S', 'š' => 's', 'Ž' => 'Z', 'ž' => 'z', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E',
            'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U',
            'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c',
            'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o',
            'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'ý' => 'y', 'þ' => 'b', 'ÿ' => 'y');
        $str = strtr($str, $unwanted_array);

        # Bullets, dashes, and trademarks 
        $str = ereg_replace(chr(149), "&#8226;", $str);    # bullet • 
        $str = ereg_replace(chr(150), "&ndash;", $str);    # en dash 
        $str = ereg_replace(chr(151), "&mdash;", $str);    # em dash 
        $str = ereg_replace(chr(153), "&#8482;", $str);    # trademark 
        $str = ereg_replace(chr(169), "&copy;", $str);    # copyright mark 
        $str = ereg_replace(chr(174), "&reg;", $str);        # registration mark 

        return $str;
    }

    /**
     * Return the list of the unsupported chars by the file system
     * 
     * @return list unsupported chars
     */
    public function getReservedChar() {
        $array = array("\\", "/", ":", "?", "\"", "<", ">", "|");
        return $array;
    }

    public function checkForReservedChar() {
        $reserved = "\*/*:*?*\"*<*>*|*";

        if (preg_match("/\bweb\b/i", "PHP is the web scripting language of choice.")) {
            echo "A match was found.";
        } else {
            echo "A match was not found.";
        }
    }

    public static function getFileSize($size) {
        $kb = 1024;
        $mb = 1048576;
        $gb = 1073741824;
        $tb = 1099511627776;
        if (!$size)
            return '0 B';
        elseif ($size < $kb)
            return $size . ' B';
        elseif ($size < $mb)
            return round($size / $kb, 2) . ' KB';
        elseif ($size < $gb)
            return round($size / $mb, 2) . ' MB';
        elseif ($size < $tb)
            return round($size / $gb, 2) . ' GB';
        else
            return round($size / $tb, 2) . ' TB';
    }

}

?>
